#ifndef EVENT_H_
#define EVENT_H_
/*********************************************************/
#include "Poco/Mutex.h"
#include "Poco/Semaphore.h"

#include <map>
#include <string>

#define SEM_MAX 1
/*********************************************************/
class Event
{
private:
	// Members
	std::string				name;
	static std::map<std::string, Event*> 	events;
	static Event*				dummy;
	Poco::Mutex				mutex;
	Poco::Semaphore				*sem;
	int					semValue;	// Current semaphore value
	int					count;		// Keeps the amount of times the event got flagged

	// Construction & Copy Construction
	Event();
	Event(const Event&);

public:
	std::string getName();					// Returns the name of the event
	void set();						// Set an event
	void wait();						// Wait for an event to be flagged
	bool tryWait(long milliseconds);			// Wait up to milliseconds for the event to become flagged
	void reset();						// Reset the event

	// Class Control
	static Event* Instance(const std::string&);		// Instance retrieval
	virtual ~Event();					// Destructor
};
/*********************************************************/
#endif //EVENT_H_